<?php


class AppController extends Controller {

/******************************************************************************/

var $components = array(
	'Session',
	'RequestHandler',
	'Auth',
	'Routines.PageTitle',
	'Admin.AutomateMethods',
	'Admin.ListingMethods',
	'Admin.EditingMethods',
	'Admin.SimpleMethods',
	'Admin.ExcelMethods',
	'Admin.ClientMethods',
	'DebugKit.Toolbar'
);

var $helpers = array(
	'Session',
	'Html',
	'Form',
	'Javascript',
	'Number', 'Time',
	'Paginator', 'Paginator2',
	'Admin.Routine'
);

/******************************************************************************/

var $Model = NULL;
var $RubricModel = NULL;
var $ItemModel = NULL;

//var $autoRender = TRUE;
var $automateRender = TRUE;

/*******************************************************************************
NEW CODE
*******************************************************************************/

var $layout = 'project';

function __mergeVars() {
	// ???
	parent::__mergeVars();
}

function _disableAll() {
	Configure::write('debug', 0);
	$this->disableCache();
	$this->autoRender = FALSE;
	@ob_clean();
}

function _setLanguage($lang = NULL) {
	if (is_null($lang) && isset($this->params['lang'])) {
		$lang = $this->params['lang'];
	}
//	} elseif (is_null($lang) && isset($this->params['language'])) {
// $this->params['language'] is deprecated, use $this->params['lang']
//$lang = $this->params['language'];
//	}
	$l10n = new L10n();
	$l10n->get($lang);
	if (!in_array($l10n->locale, (array)Configure::read('Config.languages')) && defined('DEFAULT_LANGUAGE')) {
		$l10n->get(DEFAULT_LANGUAGE);
	}
	Configure::write('Config.language', $l10n->locale);
	$this->set(array('locale' => $l10n->locale, 'lang' => $l10n->lang, 'l10n' => $l10n->catalog($l10n->lang)));
// $language is deprecated, use $lang
//$this->set('language', Configure::read('Config.language'));
}

/******************************************************************************/
/******************************************************************************/

function beforeFilter() {
	parent::beforeFilter();
	$this->_setLanguage();
	// mensshop
        if (isset($this->params['admin'])) {
                $this->Auth->userModel = 'User';                
        }
	$this->set('controller', $controller = $this->params['controller']);
	$this->set('action', $action = $this->params['action']);
	if (property_exists($this, $this->modelClass) && is_object($this->Model = $this->{$this->modelClass}) && $this->Model->isAutomated()) {
		$this->set('model', $model = $this->Model->name);
		$this->set('primary_key', $primary_key = $this->Model->primaryKey);
		$this->set('display_image', $display_image = $this->Model->displayImage);
		$this->set('display_field', $display_field = $this->Model->displayField);
		$this->set('schema', $schema = $this->Model->schema());
		$this->set('field_schema', $field_schema = $this->Model->getFieldSchema());
		$this->set('tab_schema', $tab_schema = $this->Model->getTabSchema());
		// is tree
		$this->set('is_tree', $is_tree = $this->Model->isTree());
		if ($is_tree) {
			$this->set('tree_info', $tree_info = $this->Model->getTreeInfo());
			$this->set('tree_parent_key', $tree_parent_key = $tree_info['parent']);
			$this->set('tree_left_key', $tree_left_key = $tree_info['left']);
			$this->set('tree_right_key', $tree_right_key = $tree_info['right']);
		}
		// has rubric
		$this->set('has_rubric', $has_rubric = $this->Model->hasRubric() && is_object($this->RubricModel = $this->Model->getRubricModel()) && $this->RubricModel->isAutomated());
		if ($has_rubric) {
			$this->set('rubric_info', $rubric_info = $this->Model->getRubricInfo());
			$this->set('rubric_model', $rubric_model = $this->RubricModel->name);
			$this->set('rubric_primary_key', $rubric_primary_key = $this->RubricModel->primaryKey);
			$this->set('rubric_display_image', $rubric_display_image = $this->RubricModel->displayImage);
			$this->set('rubric_display_field', $rubric_display_field = $this->RubricModel->displayField);
			// rubric is tree
			$this->set('rubric_is_tree', $rubric_is_tree = $this->RubricModel->isTree());
		}
		// has items
		$this->set('has_items', $has_items = $this->Model->hasItems() && is_object($this->ItemModel = $this->Model->getItemModel()) && $this->ItemModel->isAutomated());
		if ($has_items) {
			$this->set('item_info', $item_info = $this->Model->getItemInfo());
			$this->set('item_model', $item_model = $this->ItemModel->name);
			$this->set('item_primary_key', $item_primary_key = $this->ItemModel->primaryKey);
			$this->set('item_display_image', $item_display_image = $this->ItemModel->displayImage);
			$this->set('item_display_field', $item_display_field = $this->ItemModel->displayField);
			// items is tree
			$this->set('items_is_tree', $items_is_tree = $this->ItemModel->isTree());
		}
	}
}

function _processMetaSEO($model_data = array()) { // deprecated
	$this->AutomateMethods->_processMetaSEO($model_data);
}

function beforeRender() {
	parent::beforeRender();
	if (!(bool)Configure::read('admin')) {
		if (isset($this->viewVars['setting_row']['Setting']['project_title']) && !empty($this->viewVars['setting_row']['Setting']['project_title'])) {
			$this->PageTitle->projectTitle = $this->viewVars['setting_row']['Setting']['project_title'];    
		}
	}
}

/******************************************************************************/

function _JSON($value, $exit = TRUE) { // deprecated
	$this->AutomateMethods->JSON($value, $exit);
}

function _isAjax_JSON($value, $exit = TRUE) { // deprecated
	$this->AutomateMethods->isAjax_JSON($value, $exit);
}

function redirect($url, $status = NULL, $exit = TRUE) {
	// ajax
	$this->_isAjax_JSON($status, $exit);
	// message
	if (is_array($status)) {
		if (array_key_exists('message', $status)) $this->Session->setFlash($status['message']);
		$status = array_key_exists('code', $status) ? $status['code'] : NULL;
	}
	// status
	if (!is_null($status)) $this->Session->write('Message.status', $status);
	return parent::redirect($url, $status, $exit);
}

/******************************************************************************/

function admin_filter($rubric_id = NULL) {
	$this->ListingMethods->filter($rubric_id);
}

function admin_index($rubric_id = NULL) {
	$this->ListingMethods->index($rubric_id);
}

function admin_sub_index($rubric_id = NULL) {
	$this->autoLayout = FALSE;
	$this->AutomateMethods->disableAll();
	$this->ListingMethods->paginateLimit = FALSE;
	$this->autoRender = TRUE;
	$this->ListingMethods->index($rubric_id);
}

function admin_view($id = NULL) {
	$this->admin_edit($id);
}

/******************************************************************************/

function admin_add($rubric_id = NULL) {
	$this->EditingMethods->add($rubric_id);
}

function admin_edit($id = NULL) {
	$this->EditingMethods->edit($id);
}

function admin_delete($id = NULL) {
	$this->EditingMethods->delete($id);
}

/******************************************************************************/

function admin_toggle_field($id = NULL, $field_name = NULL) {
	$this->SimpleMethods->toggleField($id, $field_name);
}

/******************************************************************************/

function admin_lock($id = NULL) {
	$this->SimpleMethods->lock($id);
}

function admin_unlock($id = NULL) {
	$this->SimpleMethods->unlock($id);
}

function admin_toggle_locked($id = NULL) {
	$this->SimpleMethods->toggleLocked($id);
}

/******************************************************************************/

function admin_hide($id = NULL) {
	$this->SimpleMethods->hide($id);
}

function admin_show($id = NULL) {
	$this->SimpleMethods->show($id);
}

function admin_toggle_hidden($id = NULL) {
	$this->SimpleMethods->toggleHidden($id);
}

/******************************************************************************/

function admin_disable($id = NULL) {
	$this->SimpleMethods->disable($id);
}

function admin_enable($id = NULL) {
	$this->SimpleMethods->enable($id);
}

function admin_toggle_disabled($id = NULL) {
	$this->SimpleMethods->toggleDisabled($id);
}

/******************************************************************************/

function admin_erase($id = NULL) {
	$this->SimpleMethods->erase($id);
}

function admin_unerase($id = NULL) {
	$this->SimpleMethods->unerase($id);
}

function admin_toggle_deleted($id = NULL) {
	$this->SimpleMethods->toggleDeleted($id);
}

/******************************************************************************/

function admin_first($id = NULL) {
	$this->SimpleMethods->first($id);
}

function admin_top($id = NULL) {
	$this->SimpleMethods->top($id);
}

function admin_up($id = NULL, $number = 1) {
	$this->SimpleMethods->up($id, $number);
}

function admin_down($id = NULL, $number = 1) {
	$this->SimpleMethods->down($id, $number);
}

function admin_bottom($id = NULL) {
	$this->SimpleMethods->bottom($id);
}

function admin_last($id = NULL) {
	$this->SimpleMethods->last($id);
}

/******************************************************************************/

function admin_before($id = NULL, $neighbor_id = NULL) {
	$this->SimpleMethods->before($id, $neighbor_id);
}

function admin_after($id = NULL, $neighbor_id = NULL) {
	$this->SimpleMethods->after($id, $neighbor_id);
}

/******************************************************************************/

function admin_move($id = NULL, $parent_id = NULL) {
	$this->SimpleMethods->move($id, $parent_id);
}

/******************************************************************************/

function admin_move_before($id = NULL, $parent_id = NULL, $neighbor_id = NULL) {
	$this->SimpleMethods->moveBefore($id, $parent_id, $neighbor_id);
}

function admin_move_after($id = NULL, $parent_id = NULL, $neighbor_id = NULL) {
	$this->SimpleMethods->moveAfter($id, $parent_id, $neighbor_id);
}

/******************************************************************************/

function admin_drop_before($id = NULL, $neighbor_id = NULL) {
	$this->SimpleMethods->dropBefore($id, $neighbor_id);
}

function admin_drop_after($id = NULL, $neighbor_id = NULL) {
	$this->SimpleMethods->dropAfter($id, $neighbor_id);
}

/******************************************************************************/

function admin_back($id = NULL) {
	$this->SimpleMethods->back($id);
}

function admin_rubric_back($rubric_id = NULL) {
	$this->SimpleMethods->rubricBack($rubric_id);
}

/******************************************************************************/

function admin_recover() {
	$this->SimpleMethods->recover();
}

function admin_reorder() {
	$this->SimpleMethods->reorder();
}

function admin_verify() {
	$this->SimpleMethods->verify();
}

/******************************************************************************/

function admin_export() {
	$this->ExcelMethods->exportAll();
}

function admin_import() {
	$this->ExcelMethods->importAll();
}

/******************************************************************************/

function admin_export_rubric($rubric_id = NULL) {
	$this->ExcelMethods->exportRubric($rubric_id);
}

function admin_import_rubric($rubric_id = NULL) {
	$this->ExcelMethods->importRubric($rubric_id);
}

/******************************************************************************/

function admin_export_filtered() {
	$this->ExcelMethods->exportFiltered();
}

function admin_import_filtered() {
	$this->ExcelMethods->importFiltered();
}

/******************************************************************************/

function index($rubric_id = NULL) {
	$this->ClientMethods->index($rubric_id);
}

function view($id_or_slug = NULL) {
	$this->ClientMethods->viewBySlug($id_or_slug);
}

/******************************************************************************/

function rss($rubric_id = NULL) {
	//$this->FeedMethods->rss($rubric_id);
}

function atom($rubric_id = NULL) {
	//$this->FeedMethods->atom($rubric_id);
}

/******************************************************************************/

}


App::import('Controller', 'AppProject');
App::import('Controller', array('General', 'Attachment')); // deprecated


?>